package com.shell.governor.srvhall.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.shell.bee.entity.mvc.RetMsg;
import com.shell.bee.file.service.PubFileUploadService;
import com.shell.bee.report.excel.WordParser;
import com.shell.governor.srvhall.dao.PubSrvHallDao;
import com.shell.governor.srvhall.service.PubSrvHallService;
import com.shell.governor.srvhall.vo.SrvHallCategoryVo;

@Service
public class PubSrvHallServiceImpl implements PubSrvHallService {
	@Autowired
	private PubSrvHallDao pubSrvHallDao;
	@Resource(name = "${file.updownload.service}")
	private PubFileUploadService pubFileUploadService;

	public List<SrvHallCategoryVo> getSrvhallCat(String catId) {
		return this.pubSrvHallDao.getSrvhallCat(catId);
	}

	public Map<String, Object> uploadFile(MultipartFile file, String fileType, String savePath) throws Exception {
		String content = WordParser.wordToHtml(file.getInputStream(), file.getOriginalFilename(), "");
		Map<String, Object> result = new HashMap();
		if (WordParser.RESULT.UNEXIST.toString().equals(content)) {
			result.put("type", "error");
			result.put("msg", "����������");
		} else if (WordParser.RESULT.FILEERROR.toString().equals(content)) {
			result.put("type", "error");
			result.put("msg", "������������");
		} else if (WordParser.RESULT.EXCEPTION.toString().equals(content)) {
			result.put("type", "error");
			result.put("msg", "������������");
		} else {
			RetMsg retMsg = this.pubFileUploadService.saveFile(file, fileType, savePath, "");
			result.put("type", retMsg.getType());
			result.put("show", Boolean.valueOf(retMsg.isShow()));
			result.put("msg", retMsg.getMsg());
			result.put("bean", retMsg.getBean());
			result.put("content", content);
		}
		return result;
	}
}
